<?php
if (!defined("HELP_FUNCTIONS_CLASS_PHS")) {
	define("HELP_FUNCTIONS_CLASS_PHS",1);
	require_once('Constant888.class.php');
	$Constant888 = Constant888::instance();
	class HelpFunctions {		
		static public function equalsArray($a,$b) {

			if ( !is_array($a) || !is_array($b) ) return false;

			if ( count($a) != count($b) ) return false;

			foreach($a as $id => $vl) {
				if ( is_array($vl) ) {
					if ( !self::equalsArray($vl,$b[$id]) ) {
						return false;
					}
				} else
				if ( is_array($b[$id]) ) return false;
				else {
					if ( $vl != $b[$id] ) return false;
				}
			}
			return true;
		}
		
		
		/**
		 * Format a string so that fit nicely into the cellphone screen 
		 * @param $str
		 * @param $delim array of delimiters 
		 * @return mixed gives back an array of strings , each length is about MAX_SCREEN_WIDTH
		 * E.g: $str = "Ba: 49606,01948,83788,70836,42054,65750"
		 * returns: array("Ba: 49606,01948,83788,"70836,42054,65750")
		 */
		static function fitToScreen($str) {
			global $Constant888;
			$tempStr = "";
			$arr = explode(':',$str);
			$tempStr = $arr[0].": ";  //"Ba: " 			
			$arr = explode(',',$arr[1]); //array(49606,01948,83788,70836,42054,65750)
			
			$retArr = array();
			$numWinNumbers = count($arr);
			$i = 0;
			$fin = false;
			foreach($arr as $lottNumber) {
				$i++;
				$old = $tempStr;
				$tempStr .= $lottNumber;
				if ( strlen($tempStr) > $Constant888->value("MAX_SCREEN_WIDTH") ) {
					
					$retArr[] = $old;
					$tempStr = $lottNumber.',';
					if ( $i === $numWinNumbers ) {
						$fin = true;
					}
				} else $tempStr .= ',';				
			}	
			
			if ( !$fin ) $retArr[] = $tempStr;
			for($i = 0; $i < count($retArr) ; $i++) {
				$retArr[$i] = rtrim($retArr[$i],',');					
			}	
			if ( count($retArr) > 1 ) {
				$cutFirstLine = explode(':',$retArr[0]);
				for($i = count($retArr) ; $i >=2 ; $i--) {
					$retArr[$i] = $retArr[$i-1];
				}
				$retArr[1]= $cutFirstLine[1];
				$retArr[0]= $cutFirstLine[0];
			}	
			return $retArr;
		}
		
		
		/**
		 * 
		 * @param $areaCode 
		 * @return string stored file name for this area
		 */
		static function resultStoreFileName($areaCode,$index) {
			global $Constant888;
			return $Constant888 -> valueArray("STORED_RESULT_FILE_NAMES",$areaCode )."$index.xml";  
		}
		
	}
}
?>
